package db

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm_create_struct/conf"
)

var Instance *gorm.DB

func Init() {
	dsn := fmt.Sprintf(
		"%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		conf.MasterDbConfig.User,
		conf.MasterDbConfig.Pwd,
		conf.MasterDbConfig.Host,
		conf.MasterDbConfig.DbName,
	)

	var err error
	Instance, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
}